﻿using System;

namespace HW0317_2
{
    public class AlarmEventArgs
    {
        public int Second { get; set; }
        public int Length { get; set; }

    }
    public delegate void AlarmEventHandler(object sender, AlarmEventArgs args);
    public class ButtonT
    {
        public event AlarmEventHandler Tick;
        public void Set(int s)
        {
            Console.WriteLine($"...set the alarm to TICK mode...");
            AlarmEventArgs args = new AlarmEventArgs()
            {
                Second = s,
                Length = 0
            };
            Tick(this, args);
        }
    }
    public class ButtonA
    {
        public event AlarmEventHandler Alarm;
        public void Set(int l)
        {
            Console.WriteLine($"...set the alarm to ALARM mode for {l} min...");
            AlarmEventArgs args = new AlarmEventArgs()
            {
                Second = 0,
                Length = l
            };
            Alarm(this, args);
        }
    }
    public class Form
    {
        public ButtonA buttonA = new ButtonA();
        public ButtonT buttonT = new ButtonT();
        public Form()
        {
            buttonA.Alarm += Alarm_Alarm1;
            buttonA.Alarm += Alarm_Alarm2;
            buttonT.Tick += Alarm_Tick1;
            buttonT.Tick += Alarm_Tick2;
        }
        void Alarm_Alarm1(object Sender, AlarmEventArgs args)
        {
            Console.WriteLine("Your alarm has been set to ALARM mode! ");
        }
        void Alarm_Alarm2(object Sender, AlarmEventArgs args)
        {
            Console.WriteLine($"***ALARM for {args.Length} min***");
        }
        void Alarm_Tick1(object Sender, AlarmEventArgs args)
        {
            Console.WriteLine($"Your alarm has been set to TICK mode for {args.Second} s! ");
        }
        void Alarm_Tick2(object Sender, AlarmEventArgs args)
        {
            int span = args.Second;
            Console.Write("***");
            while (span >0)
            {
                Console.Write("Tick ");
                Thread.Sleep(500);
                Console.Write("Tock ");
                Thread.Sleep(500);
                span--;
            }
            Console.WriteLine("***");
           
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Form form = new Form();
            Console.Write("Enter how long you want the alarm to be in the ALARM mode: ");
            string str;
            str = Console.ReadLine();
            int length = int.Parse(str);
            Console.Write("Enter how long you want the alarm to TICK: ");
            str = Console.ReadLine();
            int second = int.Parse(str);
            form.buttonA.Set(length);
            Console.WriteLine();
            form.buttonT.Set(second);
        }
    }
}
